package cn.myframe.controller.tb;

import cn.myframe.controller.AbstractController;
import cn.myframe.controller.BaseController;
import cn.myframe.entity.tb.TbRegionEntity;
import cn.myframe.redis.RedisService;
import cn.myframe.service.BaseService;
import cn.myframe.service.tb.TbRegionService;
import cn.myframe.utils.annotation.CheckDelete;
import cn.myframe.utils.annotation.CheckNoPass;
import cn.myframe.utils.annotation.IgnoreAuth;
import cn.myframe.utils.aop.AssociateData;
import cn.myframe.utils.core.R;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 
 * 
 * @author ynz
 * @email ynz@myframe.cn
 * @date 2018-12-08 00:31:23
 */
@RestController
@RequestMapping("/tb/tbregion")
@IgnoreAuth
public class TbRegionController  extends AbstractController implements BaseController<TbRegionEntity,BaseService<TbRegionEntity>>{
	@Autowired
	private TbRegionService tbRegionService;

	/**
	 * 列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list",method = {RequestMethod.GET})
	@RequiresPermissions("tbregion:list")
	public R list(@RequestParam Map<String, Object> params){
		return this.defaultList(params);
	}	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{regionId}")
	@RequiresPermissions("tbregion:info")
	public R info(@PathVariable("regionId") Long id){
		return this.defaultInfo(id,"tbRegion");
	}
	
	/**
	 * 新增保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("tbregion:save")
	public R save(@RequestBody TbRegionEntity tbRegion){		
		return this.defaultSave(tbRegion);
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("tbregion:delete")
	@CheckDelete(AssociateData.USER_REGION)
	public R delete(@RequestBody Long[] ids){		
		return this.defaultDelete(ids);
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")	
	@RequiresPermissions("tbregion:update")
	public R update(@RequestBody TbRegionEntity tbRegion){		
		return this.defaultUpdate(tbRegion);
	}
	
	/**
	 * 复制
	 */
	@RequestMapping("/copy")
	public R copy(@RequestBody Long id){		
		return this.defaultCopy(id);
	}
	
   /**
    * 提交,审核
    */
	@RequestMapping("/audit")	
	@RequiresPermissions(value={"tbregion:submit","tbregion:auditpass","tbregion:auditnopass"},logical=Logical.OR)
	@CheckNoPass(AssociateData.USER_REGION)
	public R audit(@RequestBody Long[] ids ,@RequestParam Integer status){
		return this.defaultAudit(ids, status);
	}
	
   /**
	* 检验字段值重复
	*/
    @RequestMapping("/checkExist")
    @ResponseBody
    public String checkExist(String id,String value,String columnName){
        return this.defaultCheckExist(id, value, columnName);
    }

    @Autowired
    RedisService redisService;

	@RequestMapping("/redis")
	@ResponseBody
	@IgnoreAuth
    public String redis(){
		redisService.convertAndSend("helloRedis","hello redis");
		redisService.convertAndSend("dealUser","hello dealUser");
    	return "redis";
	}


    public TbRegionService getService(){
		return tbRegionService;
	}
	
}
